package com.green.service.common.impl;

import java.util.Collection;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.green.common.util.utils.CollectionUtils;
import com.green.service.common.BaseService;

/**
 * 基本的service
 * 
 * @author Administrator
 * 
 */
public  class BaseServiceImpl implements BaseService {
	protected Logger logger=Logger.getLogger(this.getClass());
	
	/**
	 * 对str前后加上"%"
	 * 
	 * @param str
	 * @return
	 */
	protected String toLikeStr(String str) {
		return StringUtils.isNotBlank(str) ? "%" + str.trim() + "%" : null;
	}
	protected String toNullStr(String str) {
		return StringUtils.isNotBlank(str) ? str.trim() : null;
	}
	protected String stringNoBlank(String str) {
		if (str != null && !"".equals(str)) {
			Pattern p = Pattern.compile("\t|\r|\n");
			Matcher m = p.matcher(str);
			String strNoBlank = m.replaceAll("");
			return strNoBlank;
		} else {
			return str;
		}
	}
	protected Object getCollectionFirst(Collection<? extends Object> c) {
        if(CollectionUtils.isEmpty(c))
        {
        	return null;
        }
        return c.iterator().next();
	}
	


	
}